package com.hongyuan.venue.ui.person.view_mode;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.hongyuan.mvvmhabitx.binding.command.BindingAction;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.venue.base.ItemViewModel;
import com.hongyuan.venue.data.md5.BaseUtil;
import com.hongyuan.venue.ui.home.beans.SecheduleBeans;
import com.hongyuan.venue.ui.main.activity.PayActivity;
import com.hongyuan.venue.ui.main.beans.V3SuccessBeans;
import com.hongyuan.venue.ui.person.activity.MyOrderDetailActivity;
import com.hongyuan.venue.ui.person.beans.MyOrdersBean;
import com.hongyuan.venue.utils.TimeUtil;

import java.util.ArrayList;
import java.util.List;

public class MyOrdersItemViewModel extends ItemViewModel<MyOrdersViewModel> {

    public ObservableField<MyOrdersBean.ListBean> entity = new ObservableField<>();

    public MyOrdersItemViewModel(@NonNull MyOrdersViewModel viewModel, MyOrdersBean.ListBean bean) {
        super(viewModel);
        entity.set(bean);
    }

    //取消订单
    public BindingCommand cancel = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            viewModel.itemClick(MyOrdersItemViewModel.this);

            viewModel.uc.cancelOrder.call();
        }
    });

    //去支付订单
    public BindingCommand goPay = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            Bundle bundle = new Bundle();
            bundle.putString("payPrice",entity.get().getO_money());
            bundle.putString("payOid",String.valueOf(entity.get().getO_id()));
            bundle.putSerializable("successBeans",getSuccessBeans());

            viewModel.startActivity(PayActivity.class,bundle);
        }
    });

    //去订单详情
    public BindingCommand goDetails = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putSerializable("orderBeans",entity.get());
            viewModel.startActivity(MyOrderDetailActivity.class,bundle);
        }
    });

    /*
     * 组装订单显示信息
     * */
    private V3SuccessBeans getSuccessBeans(){
        V3SuccessBeans beans = new V3SuccessBeans();
        List<V3SuccessBeans.ItemConten> list = new ArrayList<>();

        V3SuccessBeans.ItemConten itemConten;

        beans.setType(V3SuccessBeans.TYPE.BUYCARD);
        beans.setTitleText("购卡订单");
        beans.setShowText("购买成功");
        beans.setBtn2Text("完成");
        for(MyOrdersBean.ListBean.OgmMxBean listBean : entity.get().getOgm_mx()){
            itemConten = new V3SuccessBeans.ItemConten();
            itemConten.setContent(listBean.getArea_name());
            itemConten.setItemTitle("场地");
            list.add(itemConten);

            itemConten = new V3SuccessBeans.ItemConten();
            itemConten.setContent(TimeUtil.getStringByFormat(listBean.getS_time()*1000,TimeUtil.dateFormatDotYMDHM) +"-"+ TimeUtil.getStringByFormat(listBean.getE_time()*1000,TimeUtil.dateFormatHM));
            itemConten.setItemTitle("预约时间");
            list.add(itemConten);

            itemConten = new V3SuccessBeans.ItemConten();
            itemConten.setContent("￥"+listBean.getArea_price());
            itemConten.setItemTitle("价格");
            list.add(itemConten);
        }

        if(BaseUtil.isValue(entity.get().getO_coupon_money()) && Double.valueOf(entity.get().getO_coupon_money()) > 0){
            itemConten = new V3SuccessBeans.ItemConten();
            itemConten.setContent("-¥"+BaseUtil.getNoZoon(entity.get().getO_coupon_money()));
            itemConten.setItemTitle("优惠:");
            list.add(itemConten);
        }
        beans.setItemContens(list);

        return beans;
    }

}
